 
 
 
   var count = 0;
   
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        button1: cc.Button,
        button2: cc.Button,
        button3: cc.Button,
        button4: cc.Button,
        button5: cc.Button,
        button6: cc.Button,
        button7: cc.Button,
        button8: cc.Button,
        button9: cc.Button,
        score: cc.Label,
    },

    // use this for initialization
    onLoad: function () {
 
         var  node = this.node;
  var children = node.children;


    setInterval(function(){

//   var children = node.children;
    var i = 9;
    while(i == 9)
        i = Math.floor(Math.random()*10);                     // 随机0-9 之间整数
        if(!children[i].color.equals(cc.Color.RED)) {          //当前洞口是否为红色,否 则地鼠出洞
        children[i].color = new cc.Color(0,0,255);   

        setTimeout(function() {
         children[i].color = new cc.Color(255,255,255);             
        }, 1000);

    }},cc.random0To1()*2000);


        this.button1.node.on(cc.Node.EventType.TOUCH_END, this.onBtn1Clicked, this);
        this.button2.node.on(cc.Node.EventType.TOUCH_END, this.onBtn2Clicked, this);
        this.button3.node.on(cc.Node.EventType.TOUCH_END, this.onBtn3Clicked, this);
        this.button4.node.on(cc.Node.EventType.TOUCH_END, this.onBtn4Clicked, this);
        this.button5.node.on(cc.Node.EventType.TOUCH_END, this.onBtn5Clicked, this);
        this.button6.node.on(cc.Node.EventType.TOUCH_END, this.onBtn6Clicked, this);
        this.button7.node.on(cc.Node.EventType.TOUCH_END, this.onBtn7Clicked, this);
        this.button8.node.on(cc.Node.EventType.TOUCH_END, this.onBtn8Clicked, this);
        this.button9.node.on(cc.Node.EventType.TOUCH_END, this.onBtn9Clicked, this);


     
    },
    
    onBtn1Clicked: function(event){

        // 获取节点的第三种方式，使用静态方法获取，本质与第二种方法相同
      
        var child = this.node.getChildByName("button1");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
         var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        cc.log(count);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
            
        },2000)     
        }        
      
    },
    onBtn2Clicked: function(event){
        var child = this.node.getChildByName("button2");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        cc.log(count);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
           
        },2000)     
        } 
    },
    onBtn3Clicked: function(event){
        var child = this.node.getChildByName("button3");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        cc.log(count);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
            
        },2000)     
        }  
      
    },
    onBtn4Clicked: function(event){
         var child = this.node.getChildByName("button4");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
            
        },2000)     
        }  
    },
    onBtn5Clicked: function(event){
        var child = this.node.getChildByName("button5");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
            
        },2000)     
        }  
      
    },
    onBtn6Clicked: function(event){
        var child = this.node.getChildByName("button6");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
             
        },2000)     
        }  
      
    },
    onBtn7Clicked: function(event){
         var child = this.node.getChildByName("button7");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
            
        },2000)     
        }  
      
    },
    onBtn8Clicked: function(event){
        var child = this.node.getChildByName("button8");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
            
        },2000)     
        }  
      
    },
    onBtn9Clicked: function(event){
        var child = this.node.getChildByName("button9");
        if(child.color.equals(cc.Color.BLUE)){
            count+=1;
        child.color = new cc.Color(0,255,0);
        var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);

        },2000)
        }
        
        else{
       count-=1;
       var score = cc.find('score', this.node);
        score.getComponent('cc.Label').string = count.toString() ;
        child.color = new cc.Color(255,0,0);
        setTimeout(function(){
            child.color = new cc.Color(255,255,255);
             
        },2000)     
        }  
    },

  
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
